<template>
  <!-- 隐患处理 -->
  <view>
    <view v-if="listData.length > 0" class="grid-body mt-30">
      <view v-for="(item, index) in listData" :key="index" class="check grid-common">
        <view class="title flex">
          <image class="icon-style" :src="levelImages[item.managerLevel]" mode="aspectFill" />
          {{ item.managerTypeLabel }}
        </view>
        <view class="flex text">
          隐患级别：
          <text>{{ item.managerLevelLabel }}</text>
        </view>
        <view class="flex text">
          隐患编码：
          <text>{{ item.managerCode }}</text>
        </view>
        <view class="flex text">
          隐患描述：
          <text>{{ item.managerDesc || '--' }}</text>
        </view>
        <view class="flex text">
          上报人员：
          <text>{{ item.reportPersonName }}</text>
        </view>
        <view v-if="item.managerStatus === '2'" class="flex text">
          上报时间：
          <text>{{ item.createTime }}</text>
        </view>
        <view v-if="item.managerStatus === '4'" class="flex text">
          <view style="width: 44vw">计划整改结束时间：</view>
          <text>{{ item.planDealTime }}</text>
        </view>
        <view v-if="item.managerStatus === '5'" class="flex text">
          <view style="width: 30vw">实际整改时间：</view>
          <text>{{ item.actualDealTime }}</text>
        </view>
        <view class="footer-wrap">
          <view class="content-wrap"></view>
          <view class="button-wrap">
            <view class="button" @click="handle(item)">处理</view>
          </view>
        </view>
        <view class="check-right-top">
          <image
            v-if="item.managerStatus === '2' && item.acceptanceIdea === '4'"
            src="/static/images/message/fail-pass.png"
            class="icon-style"
            mode="aspectFill"
          />
          <image v-else class="icon-style" :src="statusImages[item.managerStatus]" mode="aspectFill" />
        </view>
      </view>
    </view>
    <view v-else>
      <Empty></Empty>
    </view>

    <CuFilter ref="cuFilter" :showArr="filterShowArr" @submit="filterSubmit" />
  </view>
</template>

<script>
const statusImages = {
  2: '/static/images/message/icon1-right.png', // 待审核
  4: '/static/images/message/icon2-right.png', // 待整改
  5: '/static/images/message/icon3-right.png', // 待验收
  1: '/static/images/message/icon4-right.png', // 待分派
  3: '/static/images/message/icon5-right.png', // 待审批
  11: '/static/images/message/icon6-right.png', // 延期待审核
  12: '/static/images/message/icon7-right.png' // 延期待审批
}

const levelImages = {
  1: '/static/images/treatment/icon2.png', // 重大隐患
  2: '/static/images/treatment/icon1.png' // 一般隐患
}
import { getHiddenDangerDealTodoList } from '@/api/dbd/hiddenDangerDeal'
import Empty from '@/components/cu-empty/index.vue'
import CuFilter from '@/components/cu-filter/cu-filter.vue'
import { managerStatusEnum } from '@/utils/constant.js'
import dayjs from 'dayjs'

export default {
  components: {
    Empty,
    CuFilter
  },
  data() {
    return {
      managerStatusEnum,
      listData: [],
      pageNum: 1,
      pageSize: 10,
      total: null,
      isFinished: false,
      statusImages,
      levelImages,
      filterShowArr: ['managerType', 'managerStatus', 'selectTime'],
      searchParams: {}
    }
  },
  // 筛选按钮点击
  onNavigationBarButtonTap() {
    this.$refs.cuFilter.toggle()
  },
  onBackPress(options) {
    if (options.from === 'backbutton') {
      this.back()
      return true
    }
  },
  onLoad() {
    // 重新加载页面数据 data 为 true ,触发方式 uni.$emit('reload',true)
    uni.$on('reload', (data) => {
      if (data) {
        this.initData()
      }
    })
    this.initData()
  },
  onShow() {
    this.initData()
  },
  onPullDownRefresh() {
    this.initData()
  },
  onReachBottom() {
    this.pageNum++
    this.getList()
  },
  methods: {
    back() {
      uni.reLaunch({
        url: '/pages/messages/index'
      })
    },
    filterSubmit(val) {
      this.pageNum = 1
      this.total = null
      this.searchParams = {}
      if (val.managerType) this.searchParams.managerType = val.managerType
      if (val.managerStatus) this.searchParams.managerStatus = val.managerStatus
      if (val.date[0]) this.searchParams.reportDateFrom = dayjs(val.date[0]).format('YYYY-MM-DD')
      if (val.date[1]) this.searchParams.reportDateTo = dayjs(val.date[1]).format('YYYY-MM-DD')
      this.getList()
    },
    initData() {
      this.listData = []
      this.isFinished = false
      this.pageNum = 1
      this.pageSize = 10
      this.total = null
      this.getList()
    },
    getList() {
      if (this.isFinished) {
        return
      }
      const data = {
        pageSize: 10,
        pageNum: this.pageNum,
        ...this.searchParams
      }
      if (!this.total || this.total > this.listData.length) {
        getHiddenDangerDealTodoList(data)
          .then((res) => {
            if (this.pageNum === 1) {
              this.listData = res.rows
            } else {
              this.listData.push(...res.rows)
            }
            this.total = res.total
          })
          .finally(() => {
            uni.stopPullDownRefresh()
          })
      }
    },

    /**
     * 处理
     * @param managerStatus 治理状态
     */
    handle({ managerStatus, managerId }) {
      let url = ''
      switch (managerStatus) {
        //审核
        case managerStatusEnum.REVIEW:
          url = `/pages/work/hiddenDangerDeal/review?managerId=${managerId}`
          break
        case managerStatusEnum.RECTIFY:
          url = `/pages/work/hiddenDangerDeal/rectify?managerId=${managerId}`
          break
        case managerStatusEnum.ACCEPTING:
          url = `/pages/work/hiddenDangerDeal/accept?managerId=${managerId}`
          break
        case managerStatusEnum.DISTRIBUTE:
          url = `/pages/work/hiddenDangerDeal/distribute?managerId=${managerId}`
          break
        // 待审批
        case managerStatusEnum.APPROVE:
          url = `/pages/work/hiddenDangerDeal/approve?managerId=${managerId}`
          break
        // 延期审核
        case '11':
          url = `/pages/work/hiddenDangerDeal/delay?managerId=${managerId}&status=${managerStatus}`
          break
        case '12':
          url = `/pages/work/hiddenDangerDeal/delay?managerId=${managerId}&status=${managerStatus}`
          break
        default:
          break
      }
      const _this = this
      uni.navigateTo({
        url,
        events: {
          reloadEvent: function (isReload) {
            if (isReload) {
              _this.initData()
            }
          }
        }
      })
    },

    /**
     * 转办
     */
    complaint() {
      uni.navigateTo({
        url: '/pages/hiddenDangerTreatment/treatmentDeal'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.grid-body {
  background-color: transparent;
}

.grid-common {
  margin-bottom: 30rpx;
  background-color: #fff;
  border-radius: 20rpx;
}

.items-center {
  align-items: center;
}

.info-btn {
  flex-shrink: 0;
  margin-right: 0px;
  margin-left: 10px;
}

.check {
  position: relative;

  .title {
    font-size: 34rpx;
    font-weight: 700;
  }

  .icon-style {
    width: 52rpx;
    height: 52rpx;
    margin-right: 20rpx;
  }

  .text {
    color: #999;

    text {
      width: 76%;
      color: #333;
      display: inline-block;
    }
  }

  .flex-text {
    padding-top: 24rpx;
    display: flex;
    color: #999;

    text {
      color: #333;
      display: inline-block;
    }
  }

  .bor-top {
    padding-top: 20rpx;
    border-top: 1rpx solid #d5d7e3;
  }

  .check-right-top {
    position: absolute;
    right: 20rpx;
    top: 20rpx;

    image {
      width: 100rpx;
      height: 88rpx;
    }
  }
}
</style>
